2 Problem: 10249 - The grand dinner
3 Andrés Mejía-Posada (andmej@gmail.com)
29 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
30 #define D(x) cout << #x " is " << x << endl
31 #define For(i, a, b) for (int i=(a); i<(b); ++i)
38 while (scanf("%d %d", &nteams
, &ntables
)==2 && nteams
&& ntables
){
39 int people
= 0, spots
= 0;
40 for (int i
=0; i
<nteams
; ++i
) g
[i
].clear();
41 vector
<pair
<int, int> > teams(nteams
), tables(ntables
);
42 for (int i
=0, c
; i
<nteams
; ++i
){
44 teams
[i
] = make_pair(c
, i
);
47 for (int i
=0, c
; i
<ntables
; ++i
){
49 tables
[i
] = make_pair(c
, i
);
52 if (people
> spots
){ printf("0\n"); continue; }
55 sort(teams
.begin(), teams
.end(), greater
<pair
<int, int> >());
56 sort(tables
.begin(), tables
.end(), greater
<pair
<int, int> >());
57 for (int i
=0; i
<teams
.size(); ++i
){
58 for (int j
=0; j
<tables
.size() && teams
[i
].first
> 0; ++j
){
59 if (tables
[j
].first
> 0){
62 g
[teams
[i
].second
].push_back(tables
[j
].second
);
72 for (int i
=0; i
<nteams
; ++i
){
76 if (!first
) printf(" ");